package cn.pangza.mybatisplus.entity;

import com.baomidou.mybatisplus.core.metadata.IPage;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

public class PageResult<T> implements Serializable {
    private Long pageNum;

    private Long pageSize;

    private Long total;

    private Long totalPages;

    private List<T> list = Collections.emptyList();

    public PageResult() {
    }

    public PageResult(Long pageNum, Long pageSize, Long total, List<T> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.list = list;
    }

    public PageResult(Long pageNum, Long pageSize, Long total, Long totalPages, List<T> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.totalPages = totalPages;
        this.list = list;
    }

    public Long getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(Long totalPages) {
        this.totalPages = totalPages;
    }

    public Long getPageNum() {
        return pageNum;
    }

    public void setPageNum(Long pageNum) {
        this.pageNum = pageNum;
    }

    public Long getPageSize() {
        return pageSize;
    }

    public void setPageSize(Long pageSize) {
        this.pageSize = pageSize;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public static <T> PageResult<T> generatePage(IPage<T> iPage) {
        PageResult<T> myPageResult = new PageResult<>();
        myPageResult.setList(iPage.getRecords());
        myPageResult.setPageNum(iPage.getCurrent());
        myPageResult.setTotal(iPage.getTotal());
        myPageResult.setPageSize(iPage.getSize());
        myPageResult.setTotalPages(iPage.getPages());
        return myPageResult;
    }
}
